package com.zxy.demo.java.pattern;

import java.util.regex.Pattern;

/**
 * PatternDemo.
 * 
 * Created by zxybird on 2017/12/9.
 */
public class PatternDemo {

  /**
   * 一类:豹子号(6,8,9)
   * 
   * 二类:豹子号(不是4,6,8,9)
   * 
   * 三类:五连顺子号
   * 
   * 四类:A000...00(A=1~9)
   * 
   * 五类:包含连续3~n个A(A=6,8,9)
   *
   * 废弃:连续3~n个4
   */

  public static void main(String[] args) {

    String LEVEL_1_REGEX = "^(6|8|9)\\1+$";
    String LEVEL_2_REGEX = "^(1|2|3|5|7)\\1+$";
    String LEVEL_3_REGEX = "^\\d*(?:(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){4}|(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){4})\\d*$";
    String LEVEL_4_REGEX = "^[1-9]0+$";
    String LEVEL_5_REGEX = "^\\d*(6|8|9){3}\\d*$";

    String ABANDON_REGEX = "^\\d*(4){3}\\d*$";

    Pattern level1Pattern = Pattern.compile(LEVEL_1_REGEX);
    Pattern level2Pattern = Pattern.compile(LEVEL_2_REGEX);
    Pattern level3Pattern = Pattern.compile(LEVEL_3_REGEX);
    Pattern level4Pattern = Pattern.compile(LEVEL_4_REGEX);
    Pattern level5Pattern = Pattern.compile(LEVEL_5_REGEX);

    Pattern abandonPattern = Pattern.compile(ABANDON_REGEX);

    checkAndPrint(level3Pattern, "1234");
    checkAndPrint(level3Pattern, "12345");
    checkAndPrint(level3Pattern, "123456");

    // System.out.println(abandonPattern.matcher("444").matches());
    // System.out.println(abandonPattern.matcher("44").matches());
    // System.out.println(abandonPattern.matcher("2344423").matches());
    // System.out.println(abandonPattern.matcher("2344234444456").matches());

    // for test

    String LEVEL_TEST1_REGEX = "(?:9(?=8(?=(7)))|8(?=7(?=(6)))|7(?=6(?=(5)))|6(?=5(?=(4)))){2}";
    Pattern levelTest1Pattern = Pattern.compile(LEVEL_TEST1_REGEX);
    // System.out.println(levelTest1Pattern.matcher("987654321").matches());

    // System.out.println(level3Pattern.matcher("98765").matches());
    // System.out.println(level3Pattern.matcher("9898989898").matches());
    // System.out.println(level3Pattern.matcher("111111876543111111").matches());
    // System.out.println(level3Pattern.matcher("9987654").matches());

    // System.out.println(level4Pattern.matcher("1000").matches());
    // System.out.println(level1Pattern.matcher("666").matches());
    // System.out.println(level1Pattern.matcher("777").matches());
    // System.out.println(level2Pattern.matcher("777").matches());
    // System.out.println(level1Pattern.matcher("66666").matches());
    // System.out.println(level1Pattern.matcher("888").matches());
    // System.out.println(level1Pattern.matcher("999").matches());
    // System.out.println(level1Pattern.matcher("668").matches());

    // String str = "123";
    // String regEx = "^\\d+$";
    // Pattern pattern = Pattern.compile(regEx);
    // Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
    // Matcher matcher = pattern.matcher(str);
    // boolean rs = matcher.matches();
    // System.out.println(rs);

  }

  public static void checkAndPrint(Pattern pattern, String string) {

    System.out.print(string + " :");
    System.out.print(pattern.matcher(string).matches());
    System.out.print("\n");

  }

}
